import Vue from 'vue'
import { ACCESS_TOKEN, USER_NAME } from "@/store/sys-constant"

/** 7天(毫秒) */
const oneMinute = 60*1000;
const expires = 7 * 24 * 60 * oneMinute;

export function getToken() {
  let token = Vue.ls.get(ACCESS_TOKEN);
  return token?token:'';
}

export function setToken(token, exp) {
  if(!token){
    return ;
  }
  Vue.ls.set(ACCESS_TOKEN, token, exp&&exp>oneMinute?exp*1000:expires);
}

export function removeToken() {
  Vue.ls.remove(ACCESS_TOKEN)
}

export function getUsername(){
  let username = Vue.ls.get(USER_NAME);
  return username?username:'';
}

export function setUsername(username){
  if(!username){
    return ;
  }
	Vue.ls.set(USER_NAME, username, expires);
}

export function removeUsername() {
  Vue.ls.remove(USER_NAME)
}

// export function getToken() {
// 	var v = Cookies.get(ACCESS_TOKEN);
//   return v? v:'';
// }

// export function setToken(token) {
//   return Cookies.set(ACCESS_TOKEN, token)
// }

// export function removeToken() {
//   return Cookies.remove(ACCESS_TOKEN)
// }

// export function getUsername(){
// 	return Cookies.get(USER_NAME);
// }

// export function setUsername(username){
// 	return Cookies.set(USER_NAME, username);
// }
